﻿using System;
using System.Collections.Generic;


namespace Baidu
{
    public class BaiduKit
    {
        private const string kSoundFileMsg = "m1.caf";

        private const string kApiKey = "dFaxdcFUq8nBIPg4LKm1howO";
        private const string kSecretKey = "NaN8f7evvoFTEOqiXNnORe9Z0vBSH4zm";


        public static string SendMsgPush(string msgType, string alertMsg, string from, string pushToken, int expirySeconds)
        {
            Dictionary<string, string> paramDict = new Dictionary<string, string>();

            var msgData = new
            {
                msgType = msgType,
                message = alertMsg,
                contentTitle = "iSender Msg",
                chatId = from,
                sound = kSoundFileMsg
            };

            fastJSON.JSON.Instance.Parameters.EnableAnonymousTypes = true;
            paramDict["messages"] = fastJSON.JSON.Instance.ToJSON(msgData);

            paramDict["apikey"] = kApiKey;//訪問令牌
            paramDict["user_id"] = pushToken;//用戶標識
            paramDict["msg_keys"] = msgType + from;//消息標識
            paramDict["message_expires"] = Convert.ToString(expirySeconds);//消息的過期時間，單位為秒

            return BaiduPush.PushMsg(paramDict, kSecretKey);
        }

    }
}